package cn.sq.musicserver.set.controller;


import cn.sq.musicserver.config.ResponseBean;
import cn.sq.musicserver.config.StatusCode;
import cn.sq.musicserver.config.base.BaseController;
import cn.sq.musicserver.config.base.BaseSelectSymbol;
import cn.sq.musicserver.config.entity.SymbolPlus;
import cn.sq.musicserver.music.entity.SqMusic;
import cn.sq.musicserver.playlist.entity.SqPlay;
import cn.sq.musicserver.set.entity.SqSet;
import cn.sq.musicserver.set.service.ISqSetService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import com.github.xiaoymin.knife4j.annotations.DynamicParameters;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author SQ
 * @since 2020-12-11
 */
@RestController
@RequestMapping("/set")
public class SqSetController extends BaseController<SqSet, ISqSetService> {

    @RequestMapping("/list_by_page")
    @ApiOperation(value = "根据条件查询播放列表")
    @RequiresAuthentication
//    @RequiresPermissions({"set:select"})
    @ApiOperationSupport(params = @DynamicParameters(name = "页面对象(IPage扩展对象)", properties = {
            @DynamicParameter(name = "pagesize", value = "每页长度", example = "10", required = true, dataTypeClass = String.class),
            @DynamicParameter(name = "pageindex", value = "第几页", example = "1", required = true, dataTypeClass = String.class),
            @DynamicParameter(name = "ascs", value = "正序字段", required = true, dataTypeClass = String.class),
            @DynamicParameter(name = "desc", value = "倒叙字段", required = true, dataTypeClass = String.class),
    }))
    public ResponseBean list_by_page(@RequestBody HashMap<String, String> map) {
        SymbolPlus symbolPlus = BaseSelectSymbol.select_Analysis(map);
        IPage<SqSet> sqSqSetIPage = super.base_get_list_by_page(symbolPlus);
        return StatusCode.successResponseBean(sqSqSetIPage);
    }

    /**
     * 添加
     *
     * @param sqSet
     * @return 添加结果
     */
    @RequiresPermissions({"set:add"})
    @RequiresAuthentication
    @ApiOperation(value = "添加")
    @RequestMapping("save")
    public ResponseBean save(@RequestBody SqSet sqSet) {
        boolean add = super.add(sqSet);
        return StatusCode.successResponseBean(add);
    }
    @RequiresRoles({"admin"})
    @RequiresAuthentication
    @ApiOperation(value = "删除")
    @RequestMapping("delete")
    public ResponseBean delete(@RequestBody HashMap<String, String> map) {
        SymbolPlus symbolPlus = BaseSelectSymbol.select_Analysis(map);
        boolean del = super.del(symbolPlus.getQueryWrapper());
        return StatusCode.successResponseBean(del);
    }

    @RequiresPermissions({"set:update"})
    @RequiresAuthentication
    @ApiOperation(value = "修改")
    @RequestMapping("modify")
    public ResponseBean modify(@RequestBody Map<String, String> map) {
        UpdateWrapper updateWrapper = BaseSelectSymbol.update_Analysis(map);
        boolean update = super.update(updateWrapper);
        return StatusCode.successResponseBean(update);
    }
    @ApiOperation(value = "检查服务器是否正常")
    @RequestMapping("checkingServer")
    public ResponseBean checkingServer() {
        return StatusCode.successResponseBean(true);
    }



}
